<?php

/**
 * PaylogModel.php 注释
 * 
 * @package 
 * @subpackage 
 * 
 */
class PaylogModel{
	/**
	 * 数据库对象
	 *
	 * @var Mysql
	 */
	private $db;
	
	/**
	 * 构造方法
	 *
	 * @param Mysql $db
	 */
	public function __construct($db)
	{
		$this->db = $db;
	}
	
	/**
	 * 添加
	 */
	public function add( array $value )
	{
		$v = array();
//		$v["Id"] = (int)$value["Id"];
		$v["uid"] = (int)$value["uid"];
		$v["pay"] = (int)$value["pay"];
		$v["channel"] = $value["channel"];
		$v["GameCash"] = (int)$value["GameCash"];
		$v["BeforeCash"] = (int)$value["BeforeCash"];
		$v["IP"] = (int)$value["IP"];
		$v["CreateTime"] = $value["CreateTime"];
		$v["UpdateTime"] = $value["UpdateTime"];
		$v["PlatFormOrderId"] = $value["PlatFormOrderId"];
		$v['AlreadyPay'] = (int)$value['AlreadyPay'];
		
		$this->db->insert("paylog", $v);
	}
	
	/**
	 * 修改
	 */
	public function change($Id, array $value)
	{
		$v = array();
		isset($value["uid"]) && $v["uid"] = (int)$value["uid"];
		isset($value["pay"]) && $v["pay"] = (int)$value["pay"];
		isset($value["channel"]) && $v["channel"] = $value["channel"];
		isset($value["GameCash"]) && $v["GameCash"] = (int)$value["GameCash"];
		isset($value["BeforeCash"]) && $v["BeforeCash"] = (int)$value["BeforeCash"];
		isset($value["IP"]) && $v["IP"] = (int)$value["IP"];
		isset($value["CreateTime"]) && $v["CreateTime"] = $value["CreateTime"];
		isset($value["UpdateTime"]) && $v["UpdateTime"] = $value["UpdateTime"];
		isset($value["PlatFormOrderId"]) && $v["PlatFormOrderId"] = $value["PlatFormOrderId"];

		$this->db->update("paylog", $v, 'Id=' . (int)$Id);
	}
	
	/**
	 * 删除
	 */
	public function del($Id)
	{
		$this->db->delete("paylog", 'Id=' .  (int)$Id);
	}
	
	/**
	 * 读取列表
	 *
	 * @param Integer $nowp
	 * @param Integer $per_page
	 */
	public function fetchAll($nowp, $per_page)
	{
		$where = '';		
		$totalNum = $this->db->fetchOne ('select count(*) from paylog ' . $where);
        
        require_once APP . '/application/models/Util.php';
        
        $pageInfo = Util::page ($totalNum, $per_page, $nowp);
        $start    = $pageInfo ['start'];
        $list     = $this->db->fetchAll ('select t1.*,t2.username from paylog t1
         left join user t2 on t2.uid=t1.uid
         ' . $where .' order by Id desc limit ' . $start . ',' . $per_page);
        
        return Array ('page' => $pageInfo['page'], 'list' => $list);
	}
	
	/**
	 * 显示
	 */
	public function show($Id)
	{
		return $this->db->fetchRow("select * from `paylog` where Id=\"?\"", array($Id));
	}
}